package com.wen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wen.common.R;
import com.wen.pojo.Gather;
import com.wen.pojo.Pay;
import com.wen.pojo.dto.GatherDto;
import com.wen.pojo.dto.PayDto;
import com.wen.pojo.vo.GatherVo;
import com.wen.pojo.vo.PayVo;
import com.wen.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/pay")
public class PayController {
    @Autowired
    private PayService service;

    @PostMapping("/page/{pageNum}/{pageSize}")
    public R page(@RequestBody PayVo payVo, @PathVariable Long pageNum, @PathVariable Long pageSize){
        Page<Pay> payPage = service.pageListPay(payVo, pageNum, pageSize);
        return R.ok().data("files",payPage.getRecords()).data("total",payPage.getTotal())
                .data("current",payPage.getCurrent()).data("size",payPage.getSize());
    }

    @GetMapping("payById/{id}")
    public R payById(@PathVariable String id){
        PayDto payDto = service.payById(id);
        return R.ok().data("payDto",payDto);
    }

    @GetMapping("UpPayById/{id}")
    public R UpPayById(@PathVariable String id){
        boolean flag = service.UpPay(id);
        if (flag)
            return R.ok().message("已拒绝请求");
        return R.error().message("拒绝请求失败");
    }
}
